package com.ldu.exam.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ldu.exam.model.ExamModel;
import com.ldu.exam.service.ExamService;

@RequestMapping(value="/exam")
@RestController
public class ExamController {
	@Autowired ExamService service;
	
	@GetMapping()
	public Page<ExamModel> findAll(@PageableDefault(size=20) Pageable page)
	{
		return this.service.findAll(page);
	}
	
	@GetMapping(value="/noPage")
	public List<ExamModel> findNoPage()
	{
		return this.service.findNoPage();
	}
	
	@PostMapping()
	public Object add(@RequestBody ExamModel model)
	{
		return this.service.add(model);
	}
	
	@DeleteMapping(value="/{id}")
	public Object delete(@PathVariable String id)
	{
		this.service.delete(id);
		return ResponseEntity.noContent().build();
	}
	
	@PutMapping(value="/{id}")
	public Object update(@PathVariable String id,@RequestBody ExamModel model)
	{
		return this.service.update(id, model);
	}
}
